package com.inspectortime.webapp.inspector.fee;

import java.util.Collections;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.inspectortime.domain.InspectorCompany;
import com.inspectortime.repository.Repository;
import com.inspectortime.webapp.util.HttpSessionUtils;

public class OptionalServicesListController implements Controller {
	
	private Repository repository;
	private String successView;
	
    public String getSuccessView() {
		return successView;
	}

	public void setSuccessView(String successView) {
		this.successView = successView;
	}

	public void setRepository(Repository repository) {
		this.repository = repository;
	}

	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		InspectorCompany company = HttpSessionUtils.retrieveLoggedInCompany(request, repository);
		
		ModelAndView mv = new ModelAndView(this.getSuccessView());
		if (company.getOptionalServices() != null) {
			mv.addObject("optionalServices", company.getOptionalServices());	
		} else {
			mv.addObject("optionalServices", Collections.EMPTY_LIST);
		}
        
        return mv;
	}
	
}
